package com.cherish.pattern.proxy.dynamicproxy.myproxy;

import java.lang.reflect.Method;

/**
 * @Classname MyMeiPo
 * @Date 2019/4/2 23:08
 * @Author admin
 * @Description TODO
 */
public class MyMeiPo implements MyInvocationHandler {

    private Object target;

    public Object getInstance(Object target) {
        this.target = target;
        Class c = target.getClass();
        return MyProxy.newProxyInstance(new MyClassLoader(),c.getInterfaces(),this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        this.before();
        Object obj = method.invoke(this.target,args);
        this.after();
        return obj;
    }

    private void before(){
        System.out.println("before");
    }


    private void after(){
        System.out.println("after");
    }

}
